package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "字典项管理")
@Slf4j
@RestController
@RequestMapping("/v1/dictOption")
public class DictOptionController {
    @Autowired
    private DictOptionService service;

    /**
     * 查询字典项
     * @param dictOptionQuery
     * @return
     */
    @GetMapping("select")
    public JsonResult service(DictOptionQuery dictOptionQuery){
        log.debug("查询字典项业务：{}",dictOptionQuery);
        List<DictOptionVO> list = service.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult save(@RequestBody DictOptionSaveParam dictOptionSaveParam){
        log.debug("保存字典项业务：{}",dictOptionSaveParam);
        service.save(dictOptionSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete")
    public JsonResult delete( DictOptionQuery dictOptionQuery){
        log.debug("删除字典项业务：{}",dictOptionQuery);
        service.delete(dictOptionQuery);
        return JsonResult.ok();
    }
    @GetMapping("selectDictOptionByCode/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("根据字典编码查询字典项业务：{}",code);
        List<DictOptionVO> list = service.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }
}
